/***********************************************
This provides some summary statistics on "share of terminal runs"
*****************************************************************/

/******************************
Summary statistics

Just for bachelors degrees
*******************************/
#delimit ;
set more off; 

include "./config.do" ;
set linesize 200 ; 
include "./drbvars.do" ;
cap log close; 
log using "./00.terminalruns_$date.log", replace; 
use "$datadir/sandwich_earnings_test.dta", clear; 

des;
tab nat_terminal_run, m  ; 
tab deglevl_code nat_terminal_run, m ; 

tab year_grad if nat_terminal_run == 1, m ;

tab year_grad year;

include "./restrictions.do" ;

include "./top_school.do" ;


/************************************
I need to do tabulations of "terminal runs"
by top_school by year_postgrad
**************************************/

gen year_post = year - year_grad ; 
gen x = 1 ; 

/*************************************************
Creating a few more variables:
instate_terminal run (where terminal run = 1 and national terminal run = 0 )
national terminal run (where national terminal run)
*********************************************************/
replace nat_terminal_run = 0 if nat_terminal_run == . ; 
tab nat_terminal_run ; 
tab terminal_run nat_terminal_run ; 

gen instate_terminal_run = terminal_run == 1 & nat_terminal_run == 0 ; 



collapse (mean) terminal_run  instate_terminal_run nat_terminal_run (sum) Nobs=x, by(year_post top_school) ; 

foreach var in terminal_run instate_terminal_run nat_terminal_run { ; 
    bys year_post: egen `var'_top = sum(`var'*(top_school==1)) ;
    bys year_post: egen `var'_nottop = sum(`var'*(top_school==0)) ;
} ; 

bys year_post: egen Nobs_total = sum(Nobs) ;

collapse (first) *terminal* Nobs_total, by(year_post); 
keep year_post *_top *_nottop Nobs ;

list ; 


outsheet using $supportdir/support_terminalruns_$date.csv, replace comma ; 

drbvars terminal_run_top, replace ;

drbvars terminal_run_nottop, replace ;

outsheet year_post terminal* using $supportdir/terminal_runs_$date.csv, replace comma ; 